package com.insea.webapp.action;


import java.util.List;

import com.insea.model.Patient;

public class PatientAction extends BaseAction{
	
	private Patient patient;
	public String query;
	private List patients;
	
	private String id;
	

	

	public Patient getPatient() {
		return patient;
	}

	public void setPatient(Patient patient) {
		this.patient = patient;
	}
	
	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}
	public List getPatients() {
		return patients;
	}

	public void setPatients(List patients) {
		this.patients = patients;
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public String save() throws Exception {
		
		if(patient.getId()==null){
			patientManager.savePatient(patient);
			String key = "patient.added";
			saveMessage(getText(key));
			
		}else{
			
			patientManager.save(patient);
			String key = "patient.updated";
			saveMessage(getText(key));
		}

	        return SUCCESS;
	}
   
	public String afficher(){
		
		if(id==null){
			patient= new Patient();
		}else{
			patient=patientManager.get(Long.valueOf(id));
			
		}
		return SUCCESS;
		
	}
	
	public String list(){
		if(query == null || "".equals(query)){
			patients = patientManager.getAll();	
		}else{
			patients = patientManager.getPatientsByName(query);
		}
		
		return SUCCESS;
	}
	
	
	
}
